<template>
  <view class="main"></view>
</template>

<script>
export default {
  data() {
    return {};
  },
  onLoad() {
    // setTimeout(() => {
    //   uni.switchTab({
    //     url: '/pages/tabbar/home'
    //   });
    // }, 3000)
    this.loadExecution();
  },
  methods: {
    loadExecution: function () {
      /**
       * 获取本地存储中launchFlag的值
       * 若存在，说明不是首次启动，直接进入首页；
       * 若不存在，说明是首次启动，进入引导页；
       */
      try {

        const value = uni.getStorageSync('launchFlag');
        // const islogin = uni.getStorageSync('isLogin') || false
        // getApp().globalData.isLogin = islogin
        if (value) {
          if (value == true) {
            uni.switchTab({
              url: '/pages/index/index'
            });

          } else {
            uni.setStorageSync('launchFlag', true);
            uni.redirectTo({
              url: '/pages/init/guide'
            });
          }
        } else {
          uni.setStorageSync('launchFlag', true);
          uni.redirectTo({
            url: '/pages/init/guide'
          });
        }
      } catch (e) {
        // error
        uni.setStorage({
          key: 'launchFlag',
          data: true,
          success: function () {
            console.log('error时存储launchFlag');
          }
        });
        uni.redirectTo({
          url: '/pages/init/guide',
        });
      }
    }
  }
};
</script>
<style></style>
